<?php

/**
 * 开发者Domain 类
 * @author: 喵了个咪  <wenzhenxi@vip.qq.com> 2015-07-23
 */
class Domain_Api {

    /**
     * 通过项目名获取接口清单
     */
    public function getApiList($uId, $projectId) {
        
        //通过项目的ID 获取有哪些接口
        $Model_ProjectApi = new Model_ProjectApi();
        $rs               = $Model_ProjectApi->getpIdByapiIdList($projectId);
        $apiIdList        = array();
        foreach ($rs as $v) {
            $apiIdList[] = DI()->base->getIndex($v, 'apiId');
        }
        //通过APIId列表获取接口清单
        $Model_Api = new Model_Api();
        $apilist   = $Model_Api->getapiIdListByapiList($apiIdList);
        if (!$apilist) {
            throw new PhalApi_Exception_BadRequest(T('No apiIdList'));
        }
        return $apilist;
    }

    /**
     * 添加权限和API关联
     */
    public function setapiListOrpriId($apiList, $priId) {

        $Model_PrivilegeApi = new Model_PrivilegeApi();
        foreach ($apiList as $v) {
            $Model_PrivilegeApi->insert(array('priId' => $priId, 'apiId' => $v));
        }
    }

    /**
     * 删除权限和API关联
     */
    public function delapiListOrpriId($priId) {

        $Model_PrivilegeApi = new Model_PrivilegeApi();
        $Model_PrivilegeApi->delapiListOrpriId($priId);
    }
}